<template>
  <div class="components-container">
    <div class="header-form">
      <div class="layui-inline">
        <label class="layui-form-label">开始日期</label>
        <div class="layui-input-inline">
          <el-date-picker v-date v-model="selectData.BSBSTARTDATE" type="date" placeholder="请选择日期" @change="btnSearch">
          </el-date-picker>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">结束日期</label>
        <div class="layui-input-inline">
          <el-date-picker v-date v-model="selectData.BSBDATE" type="date" placeholder="请选择日期" @change="btnSearch">
          </el-date-picker>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">员工姓名</label>
          <div class="layui-input-inline">
            <el-input v-model="selectData.staName" placeholder="请输入姓名"></el-input>
          </div>
      </div>
      <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">搜索</el-button>
      <el-button @click="btnRepeat">重置</el-button>
    </div>
    <!-- 功能列表 -->
    <div>
      <ul class="toolList">
        <li><el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button></li>
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <!-- 数据列表 -->
    <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" :hiddenPageOrder="false" @selectRow="selectRow" :hiddenColumn="hiddenColumn"></dataTable>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-form-item {
  margin-bottom: 0px;
}
.btnCenter {
  text-align: center;
}
</style>
<script>
import apiBase from "@/api/apiBase.js";
import dataTable from "@/components/Table/DataTable";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";

const ADD = '新增';
export default {
  name: "creUse",
  mixins: [manage],
  data() {
    return {
      selectData: {
        BSBDATE: null,
        BSBSTARTDATE: null,
        staName: null,
      },
      // 火化工
      isUse: null,
      hiddenColumn: false,
    };
  },
  methods: {
    //功能操作
    operate(order) {
      this.order = order;
      switch (this.order) {
        case ADD:
          this.$refs.dialog.open(this.order);
          break;
        default:
      }
    },
    btnShow(val){
      switch(val){
        case ADD:
          return true;
          break;
        default:
      }
    },
    //获取表头
    getCreColumn() {
      apiBase.DoService(
        {},
        apiBase.getApiAdress().Column.GetSearchSubsidyColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    //获取查询数据
    getData() {
      var data = {};
      let Data = JSON.parse(JSON.stringify(this.selectData));
      data.BSBSTARTDATE = formatDate(Data.BSBSTARTDATE, "yyyyMMdd");
      data.BSBDATE = formatDate(Data.BSBDATE, "yyyyMMdd");
      data.staName=Data.staName
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Subsidy.SearchSubsidy,
        res => {
          this.dataList = res.data.content;
          this.pageOrder.totalNum = res.data.content.RecordCount;
          // this.dataList.forEach(data => {
          //   data.CRHBEGDATE = data.CRHBEGDATE.substring(0, 16);
          //   data.CRHENDDATE = data.CRHENDDATE.substring(0, 16);
          // });
        }
      );
    },

    //重置查询
    btnRepeat() {
      this.selectData.staName=null;
      this.selectData.BSBSTARTDATE = new Date();
      this.selectData.BSBSTARTDATE.setDate(1);
      this.selectData.BSBDATE = new Date();
      this.getData();
    },
  },

  components: {
    dataTable
  },
    //路由的时候刷新组件
  activated() {
    this.getData();
  },
  created() {
    this.selectData.BSBSTARTDATE = new Date();
    this.selectData.BSBSTARTDATE.setDate(1);
    this.selectData.BSBDATE = new Date();
    this.getCreColumn();
    this.getData();
  }
};
</script>